<template>
  <div class="body">
    <!-- 搜索 -->
    <div class="ser_div">
      <el-row>
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 订单号 </el-col>
            <el-col :span="16">
              <el-input v-model="ser.order_number" type="number"></el-input>
            </el-col>
          </el-row>
        </el-col>
        <!-- <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 流水号 </el-col>
            <el-col :span="16">
              <el-input v-model="ser.serial_number"></el-input>
            </el-col>
          </el-row>
        </el-col> -->
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 客户 </el-col>
            <el-col :span="16">
              <el-select v-model="ser.customer_id" clearable filterable placeholder="请选择客户" style="width: 100%">
                <el-option v-for="(item, index) in CustomerList" :key="index" :label="item.customer_name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 产品 </el-col>
            <el-col :span="16">
              <el-select v-model="ser.product_id" clearable filterable @change="product_id_change" placeholder="请选择产品"
                style="width: 100%">
                <el-option v-for="(item, index) in productList" :key="index" :label="item.product_name" :value="item.id">
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 型号 </el-col>
            <el-col :span="16">
              <el-select filterable clearable v-model="ser.model_number_id" placeholder="请选择型号" style="width: 100%">
                <el-option v-for="(item, index) in ModelNumberList" :key="index" :label="item.model_number"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>
        <!-- <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 是否已收余款 </el-col>
            <el-col :span="16">
              <el-select
                filterable
                v-model="ser.is_residual_payment"
                style="width:60%"
              >
                <el-option
                  label="是"
                  :value="1"
                >
                </el-option>
                <el-option
                  label="否"
                  :value="2"
                >
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col> -->
        <el-col>
          <el-row style="display: flex; align-items: center">
            <el-col :span="8" style="text-align: center"> 订单日期范围 </el-col>
            <el-col :span="16">
              <el-date-picker v-model="order_data" @change="order_data_change" value-format="yyyy-MM-dd" type="daterange"
                range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
              </el-date-picker>
            </el-col>
          </el-row>
        </el-col>
        <el-col>
          <el-button @click="search(0)" class="add_btn" icon="el-icon-search">查询</el-button>
          <el-button @click="searchreset" icon="el-icon-refresh" class="add_btn">重置</el-button>
          <!-- <el-button type="primary" @click="prints()" class="add_btn">打印标签</el-button> -->
          <!-- <el-button @click="prin" class="add_btn">打印合格证</el-button> -->
          <!-- <el-button @click="search(2)" icon="el-icon-plus" class="add_btn"
            >导出</el-button
          > -->
        </el-col>
      </el-row>
    </div>
    <el-table :data="ChildList" @selection-change="handleSelectionChange" style="width: 100%" v-loading="loading"
      header-cell-class-name="header_style" border>
      <el-table-column type="selection"></el-table-column>
      <!-- <el-table-column prop="id" label="ID" width="60"> </el-table-column> -->
      <el-table-column prop="order_number" label="订单号" width="80">
      </el-table-column>
      <!-- <el-table-column prop="serial_number" label="流水号" width="80">
      </el-table-column> -->
      <el-table-column prop="serial_number" label="客户" width="100">
        <template slot-scope="scope">
          {{ scope.row.customer ? scope.row.customer.customer_name : '' }}
        </template>
      </el-table-column>
      <el-table-column prop="delivery_address" label="送货地址" width="100">
        <template slot-scope="scope">
          {{ scope.row.delivery_address }}
        </template>
      </el-table-column>
      <!-- <el-table-column prop="order_date" label="业务员" width="80">
        <template slot-scope="scope">
          {{ scope.row.account_executive.company_name }}
        </template>
      </el-table-column> -->

      <el-table-column prop="order_date" label="产品名称" width="80">
        <template slot-scope="scope">
          {{ scope.row.product ? scope.row.product.product_name : '' }}
        </template>
      </el-table-column>
      <el-table-column prop="order_date" label="型号" width="80">
        <template slot-scope="scope">
          {{ scope.row.model_number ? scope.row.model_number.model_number : '' }}
        </template>
      </el-table-column>
      <!-- <el-table-column  label="型号图片" width="80">
        <template slot-scope="scope">
          <img :src="uploadImgUrl+scope.row.model_number.file.file_url" @click="push_img(scope.row)"  style="cursor: pointer;display:block;width:60px;display: block;margin: 0 auto;" v-if="scope.row.model_number.file!=null"/>
          <img src="../../../src/assets/zwtp.jpg" style="width:60px;display: block;margin: 0 auto;"  v-else/> 
        </template>
      </el-table-column> -->
      <el-table-column label="规格" width="80">
        <template slot-scope="scope">
          {{
            scope.row.specification ? scope.row.specification.specification : ""
          }}
        </template>
      </el-table-column>
      <!-- <el-table-column prop="direction" label="方向" width="80">
      </el-table-column> -->
      <el-table-column label="颜色" width="80">
        <template slot-scope="scope">
          {{ scope.row.color ? scope.row.color.color : '' }}
        </template>
      </el-table-column>
      <el-table-column label="尺寸" width="80">
        <template slot-scope="scope">
          {{ scope.row.models_field ? scope.row.models_field.size : '' }}
        </template>
      </el-table-column>
      <!-- <el-table-column prop="receivables" label="应收款" width="120" v-if="userInfo=='超级管理员'">
      </el-table-column>
       <el-table-column prop="received" label="定金" width="120" v-if="userInfo=='超级管理员'">
      </el-table-column>  -->
      <!-- <el-table-column label="件数" width="120">
        <template slot-scope="scope">
          {{ scope.row.models_field.cases_num }}
        </template>
      </el-table-column> -->
      <!-- <el-table-column  label="折扣" width="120">
        <template slot-scope="scope">
          {{scope.row.models_field?scope.row.models_field.discount*100+'%':''}}
        </template>
      </el-table-column>
      <el-table-column  label="余款" width="120">
        <template slot-scope="scope">
          {{scope.row.models_field?scope.row.models_field.residual_payment:''}}
        </template>
      </el-table-column>
      <el-table-column
        label="收款时间"
        width="120"
      >  
      <template slot-scope="scope"> {{scope.row.models_field?scope.row.models_field.collection_time:''}}</template>
     
      </el-table-column>
      <el-table-column  label="是否已收余款" width="120">
        <template slot-scope="scope">
          {{scope.row.is_residual_payment==1?'是':'否'}}
        </template>
      </el-table-column> -->
      <!-- <el-table-column  label="订单等级" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.models_field.level==0">全部</span>
          <span v-if="scope.row.models_field.level==1">一级</span>
          <span v-if="scope.row.models_field.level==2">二级</span>
          <span v-if="scope.row.models_field.level==3">三级</span>
        </template>
      </el-table-column> -->

      <el-table-column label="紧急程度" width="80">
        <template slot-scope="scope">
          <span v-if="scope.row.emergency_procedure == 1" style="color: #333">普通</span>
          <span v-if="scope.row.emergency_procedure == 2" style="color: #1890ff; font-weight: bold">紧急</span>
          <span v-if="scope.row.emergency_procedure == 3" style="color: #ff0000; font-weight: bold">十万火急</span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="order_date" label="下单日期" :formatter="formatterTime" width="100">
      </el-table-column> -->
      <el-table-column prop="delivery_date" label="交货日期" :formatter="formatterTime" width="100">
      </el-table-column>
      <!-- <el-table-column label="审核状态" width="80">
        <template slot-scope="scope">
          {{ scope.row.status == 1 ? "已通过" : "未审核" }}
        </template>
      </el-table-column> -->
      <el-table-column prop="remark" label="备注" width="300">
        <template slot-scope="scope">
          <span
            style="display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 3;overflow: hidden;">{{ scope.row.remark }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="400" fixed="right">
        <template slot-scope="scope">
          <el-row style="display: flex; align-items: center">
            <el-col :span="20">
              <div class="uls">
                <div v-for="(ite, index) in scope.row.order_child" :key="index" :class="[
                  'lis',
                  ite.status == 1
                    ? 'wancheng'
                    : ite.status == 2
                      ? 'unwancheng'
                      : 'unpush',
                  (ite.is_appoint == 2) &
                    (ite.is_epiboly == 1) &
                    (ite.status == 2)
                    ? 'unwanchengs'
                    : '',
                ]" @dblclick="db_pushorder(ite, scope.row)">
                  <span style="
                      font-size: 12px;
                      transform: scale(0.8, 0.8);
                      *font-size: 10px;
                    ">{{ ite.job_type ? ite.job_type.job_type : "" }}</span>
                  <span style="
                      font-size: 14px;
                      transform: scale(0.8, 0.8);
                      *font-size:12px;
                    ">{{ ite.employee ? ite.employee.employee_name : '' }}</span>
                  <span style="
                      font-size: 12px;
                      transform: scale(0.8, 0.8);
                      *font-size: 10px;
                    ">
                    {{
                      ite.status == 1
                      ? "已完成"
                      : ite.status == 2
                        ? "加工中"
                        : (ite.is_appoint == 2) & (ite.is_epiboly == 2)
                          ? "未领取"
                          : "未领取"
                    }}</span>
                </div>
              </div>
            </el-col>
            <el-col :span="4" style="flex: 1; text-align: center">
              <el-dropdown trigger="click">
                <el-button type="primary" size="small">
                  操作<i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item>
                    <el-button type="text" v-permission="['dingdanjindu_more']"
                      @click="set_products(scope.row)">领单详情</el-button>
                  </el-dropdown-item>
                  <el-dropdown-item>
                    <el-popconfirm v-permission="['dingdanjindu_shanchu']" confirm-button-text="确定"
                      cancel-button-text="取消" icon="el-icon-info" icon-color="red" title="确定删除此订单吗？"
                      @confirm="del_Order(scope.row.id)">
                      <el-button slot="reference" type="text">删除</el-button>
                    </el-popconfirm>
                  </el-dropdown-item>
                  <el-dropdown-item>
                    <el-popconfirm confirm-button-text="确定" cancel-button-text="取消" icon="el-icon-info" icon-color="red"
                      title="确定将此订单添加到成品库吗？" @confirm="add_chengpin(scope.row.id)">
                      <el-button slot="reference" type="text" v-if="scope.row.production_status == 0">添加到成品库</el-button>
                    </el-popconfirm>
                  </el-dropdown-item>

                </el-dropdown-menu>
              </el-dropdown>
            </el-col>
          </el-row>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background @prev-click="prev"
        @next-click="next" :current-page.sync="pagination.page" :page-sizes="[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]"
        :page-size="pagination.per_page" layout="sizes,total, prev, pager, next" :total="total">
      </el-pagination>
    </div>

    <el-dialog title="生产信息" :visible.sync="isset_1" width="30%" :close-on-click-modal="false" @close="close_dialog">
      <el-row v-if="push_order.is_epiboly == 1">
        <el-col>
          <span style="color: crimson; font-size: 16px">*当前订单已外包*</span>
        </el-col>
      </el-row>
      <el-row v-if="push_order.is_appoint == 1">
        <el-col>
          <span style="color: crimson; font-size: 16px">*当前订单已指派*</span>
        </el-col>
      </el-row>
      <!-- <el-row
        style="height: 40px;line-height: 40px;display: flex;align-items: center;">
        <el-col :span="3"> 工序ID </el-col>
        <el-col :span="21">
          {{ push_order.id }}
        </el-col>
      </el-row> -->
      <el-row style="
          height: 40px;
          line-height: 40px;
          display: flex;
          align-items: center;
        ">
        <el-col :span="3"> 当前工序 </el-col>
        <el-col :span="21" v-if="push_order.job_type">
          {{ push_order.job_type.job_type }}
        </el-col>
      </el-row>
      <!-- v-if="push_order.is_appoint == 1" -->
      <el-row  style="height: 40px;line-height: 40px;display: flex;align-items: center;">
        <el-col :span="3"> 领单人 </el-col>
        <el-col :span="21">
          <!-- 恒泰 -->
          <!-- <el-select v-model="push_order.employee_user_id" placeholder="请选择工人" style="width: 100%">
            <el-option v-for="(item, index) in pushCustomerList" :key="index" :label="item.user.employee_name"
              :value="item.user_id">
            </el-option>
          </el-select> -->

          <!-- 暮轩 -->
          <el-select v-model="push_order.employee_user_id" placeholder="请选择工人" style="width: 100%">
            <el-option v-for="(item, index) in pushCustomerList" :key="index" :label="item.employee.employee_name"
              :value="item.pivot.user_id">
            </el-option>
          </el-select>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isset_1 = false" type="primary" size="small">取消</el-button>
        <el-button @click="push_set_1" v-permission="['dingdanjindu_pushset']" type="primary" size="small">完成</el-button>
      </span>
    </el-dialog>

    <el-dialog title="生产订单领取及完成情况表" :visible.sync="isProducts" width="60%" :close-on-click-modal="false"
      @close="isProducts_close">
      <el-table :data="moreList" stripe @selection-change="handleSelectionChang" style="width: 100%" border>
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="serial_number" label="工种" width="150">
          <template slot-scope="scope">
            <span>{{ scope.row.job_type.job_type }}</span>
          </template>
        </el-table-column>
        <el-table-column label="领单人">
          <template slot-scope="scope">
            <span v-if="scope.row.is_epiboly == 1 || scope.row.employee"
              :style="{ color: scope.row.is_epiboly == 1 ? 'red' : '' }">{{
                scope.row.is_epiboly == 1
                ? "外包"
                : scope.row.employee.employee_name
              }}</span>
          </template>
        </el-table-column>
        <el-table-column label="指派日期">
          <template slot-scope="scope">
            <span v-if="scope.row.is_epiboly == 1|| scope.row.employee">{{ scope.row.is_epiboly == 1 ?
              scope.row.epiboly_time : scope.row.appoint_time
            }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="draw_time" label="领单日期" width="170">
        </el-table-column> -->
        <el-table-column prop="submit_time" label="完成日期">
        </el-table-column>
        <el-table-column label="操作" width="150" fixed="right">
          <template slot-scope="scope">
            <el-popconfirm confirm-button-text="确定" cancel-button-text="取消" icon="el-icon-info" icon-color="red"
              title="确定外包该订单吗？" @confirm="set_waibaos(scope.row)">
              <el-button slot="reference" type="text" style="margin-right: 10px"
                v-if="scope.row.draw_time == null && scope.row.is_epiboly == 2 && scope.row.submit_time == null">外包</el-button>
            </el-popconfirm>
            <el-button style="margin-right: 10px" @click="set_yuangong(scope.row)" type="text"
              v-if="scope.row.submit_time == null">指派</el-button>
            <el-popconfirm confirm-button-text="确定" cancel-button-text="取消" icon="el-icon-info" icon-color="red"
              title="确定外包该订单吗？" @confirm="setqx_yuangong(scope.row)">
              <el-button slot="reference" type="text" style="margin-left: 10px"
                v-if="scope.row.draw_time && scope.row.is_appoint == 1 && scope.row.submit_time == ''">取消指派</el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="add_dayinpush" type="primary" size="small">添加到打印列表</el-button>
        <el-button @click="isProducts = false" type="primary" size="small">确定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="指派" :visible.sync="isset" width="30%" :close-on-click-modal="false"
      v-if="moreLists.id && push_more.id">
      <el-row style="
          height: 50px;
          line-height: 50px;
          display: flex;
          align-items: center;
        ">
        <el-col :span="3"> 订单ID </el-col>
        <el-col :span="21">
          {{ moreLists.id }}
        </el-col>
      </el-row>
      <el-row style="
          height: 50px;
          line-height: 50px;
          display: flex;
          align-items: center;
        ">
        <el-col :span="3"> 产品名 </el-col>
        <el-col :span="21">
          {{ moreLists.product.product_name }}
        </el-col>
      </el-row>
      <el-row style="
          height: 50px;
          line-height: 50px;
          display: flex;
          align-items: center;
        ">
        <el-col :span="3"> 订单型号 </el-col>
        <el-col :span="21">
          {{ moreLists.model_number.model_number }}
        </el-col>
      </el-row>
      <el-row style="
          height: 50px;
          line-height: 50px;
          display: flex;
          align-items: center;
        ">
        <el-col :span="3"> 当前工序 </el-col>
        <el-col :span="21">
          {{ push_more.job_type.job_type }}
        </el-col>
      </el-row>
      <el-row style="
          height: 50px;
          line-height: 50px;
          display: flex;
          align-items: center;
        ">
        <el-col :span="3"> 员工名称 </el-col>
        <el-col :span="21">
          <!-- 恒泰 -->
          <!-- <el-select v-model="push_prder.employee_user_id" placeholder="请选择员工" style="width: 100%">
            <el-option v-for="(item, index) in pushCustomerList" :key="index" :label="item.user.employee_name"
              :value="item.user_id">
            </el-option>
          </el-select> -->

          <!-- 暮轩 -->
          <el-select v-model="push_prder.employee_user_id" placeholder="请选择员工" style="width: 100%">
            <el-option v-for="(item, index) in pushCustomerList" :key="index" :label="item.employee.employee_name"
              :value="item.pivot.user_id">
            </el-option>
          </el-select>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isset = false">取消</el-button>
        <el-button @click="push_set">确定</el-button>
      </span>
    </el-dialog>

    <bigimg :imgurl="bigurl" :product="bigproduct" :model_number="bigmodel_number" ref="img_big"></bigimg>
  </div>
</template>
<script>
import {
  getOrderChildList,
  getUserListByJobTypeId,
  setOrderChildStatus,
  getOrderChildListByOrderId,
  assignOrderChild,
  epibolyOrderChild,
  getCustomerList,
  getModelNumberList,
  getProductList,
  addOrderPrint,
  drawOrderChildByEmployeeCardNumnber,
  delOrder,
  getUserListByModelNumberId,
  cancelAssignOrderChild,
  orderChildAddFinish
} from "@/api/product/index";
import bigimg from "@/components/bigimg";
export default {
  components: {
    bigimg,
  },
  data() {
    return {
      loading: true,
      order_ids: "",
      formatterTime(row, column) {
        let data = row[column.property];
        return /\d{4}-\d{1,2}-\d{1,2}/g.exec(data);
      },
      bigurl: "",
      bigproduct: "",
      bigmodel_number: "",
      uploadImgUrl: this.$global.imgQianJui,
      // 搜索
      multipleSelection: [],
      multipleSelections: [],
      ModelNumberLists: [],
      ModelNumberList: [],
      order_data: [],
      ser: {
        serial_number: "",
        model_number_id: "",
        order_number: "",
        customer_id: "",
        product_id: "",
        order_date: "",
        is_replenishment: "",
        is_stock_up: "",
        start_time: "",
        end_time: "",
        is_residual_payment: ''
      },
      CustomerList: [],
      productList: [],

      isset_1: false,
      moreList: [],
      moreLists: {},
      isProducts: false,
      customerList_s: [],

      pagination: {
        per_page: 40,
        page: 1,
      },
      total: 0,
      rules: {},
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7;
        },
      },
      isset: false,
      ChildList: [],
      pushCustomerList: [], //指定工种员工列表
      push_order: {},
      // 指派提交数据
      push_prder: {
        child_order_id: "",
        employee_user_id: "",
      },
      push_more: {},
      order_id: "",
      parent_username: "",
      model_number_idsss: '',
      dayinlist: [],
      dayinlist_biaoqian: [],
      role_name: ''
    };
  },
  mounted() {
    this.get_childList();
    this.getproduct();
    this.getModel();
    this.getCustomer();
    this.parent_username = this.$store.getters.userInfo.parent_username;
    this.userInfo = this.$store.getters.userInfo.role_name;
  },
  methods: {
    add_chengpin(id) {
      orderChildAddFinish({ order_id: id }).then(res => {
        if (res.code == 200) {
          this.$message.success("操作成功");
          this.get_childList();
        }
      })
    },
    handleSelectionChange(val) {
      this.dayinlist = val;
      this.dayinlist_biaoqian = val;
    },
    prin() {
      console.log(this.dayinlist);
      if (this.dayinlist.length > 0) {
        const routerurl = this.$router.resolve({
          name: "orderdayin",
          path: "/dayin",
          query: {
            data: JSON.stringify(this.dayinlist),
          },
        });
        window.open(routerurl.href, "_blank");
      } else {
        this.$message({
          type: "error",
          message: "请勾选数据",
        });
        return false;
      }
    },
    prints() {
      if (this.dayinlist_biaoqian.length == 1) {
        this.biaoqian_num = this.dayinlist_biaoqian[0].num;
        this.dayinlist_biaoqian[0].biaoqian_name = "";
        // this.isbiaoqian = true;
        const routerurl = this.$router.resolve({
          name: "biaoqian",
          path: "/biaoqian",
          query: {
            data: JSON.stringify(this.dayinlist_biaoqian),
          },
        });
        window.open(routerurl.href, "_blank");
      } else {
        if (this.dayinlist_biaoqian.length == 0) {
          this.$message({
            type: "error",
            message: "请勾选数据",
          });
          return false;
        }
        if (this.dayinlist_biaoqian.length > 1) {
          this.$message({
            type: "error",
            message: "只能选择一条数据",
          });
          return false;
        }
      }
    },
    del_Order(id) {
      delOrder({ id }).then((res) => {
        if (res.code == 200) {
          this.$message.success("操作成功");
          this.isProduct = false;
          this.get_childList();
        }
      });
    },
    push_img(row) {
      this.bigurl = row.model_number.file.file_url;
      this.bigproduct = row.product.product_name;
      this.bigmodel_number = row.model_number.model_number;
      this.$refs.img_big.open();
    },
    add_dayinpush() {
      if (this.multipleSelection.length == 0) {
        this.$message.error("请选择子订单");
        return false;
      }
      let noling = [];
      let ids = []
      for (var i = 0; i < this.multipleSelections.length; i++) {
        if (
          this.multipleSelections[i].employee == null &&
          this.multipleSelections[i].is_epiboly == 2 &&
          this.multipleSelections[i].is_appoint == 2
        ) {
          this.$message.error("所选订单有未指派的订单！请指派后在添加~");
          return false;
        }
        if (!this.multipleSelections[i].draw_time) {
          let obj = {
            user_id: this.multipleSelections[i].employee_user_id,
            order_child_id: this.multipleSelections[i].id,
          };
          // 没有领单的
          noling.push(obj);
        } else {
          // 有领单的
          ids.push(this.multipleSelections[i].id)
        }
      }
      // 有领单的
      if (ids.length > 0) {
        this.dayin_2(ids)
      }
      // 没有领单的
      if (noling.length > 0) {
        noling.forEach((item) => {
          this.postw_drawOrderChildByEmployeeCardNumnber(
            item.user_id,
            item.order_child_id
          );
        });
      }
    },
    postw_drawOrderChildByEmployeeCardNumnber(user_id, order_child_id) {
      let obj = {
        order_child_id,
        user_id,
        parent_username: this.parent_username,
      };
      drawOrderChildByEmployeeCardNumnber(obj).then((res) => {
        if (res.code == 200) {
          this.getOrderChild(this.order_ids);
          this.dayin(this.order_ids, order_child_id)

        } else {
          this.$message.error("领单失败");
        }
      });
    },
    isProducts_close() {
      this.order_ids = ''
    },
    dayin_2(ids) {
      let obj = {
        order_id: this.order_ids,
        order_child_ids: ids,
      };
      addOrderPrint(obj).then((res) => {
        if (res.code == 200) {
          this.$message.success("添加成功");
        }
      });
    },
    dayin(id, ids) {
      let id_s = [];
      id_s.push(ids)
      let obj = {
        order_id: id,
        order_child_ids: id_s,
      };
      addOrderPrint(obj).then((res) => {
        if (res.code == 200) {
          this.$message.success("添加成功");
        }
      });
    },

    handleSelectionChang(val) {
      if (val.length > 0) {

        this.multipleSelections = val;
        this.order_id = val[0].order_id;
        this.multipleSelection = [];
        val.forEach((item) => {
          let obj = {
            user_id: item.employee_user_id,
            order_child_id: item.id,
          };
          this.multipleSelection.push(obj);
        });
      } else {
        this.multipleSelection = [];
      }
    },
    // 指定查询
    search(type) {
      if (type == 0) {
        this.pagination.per_page = 10;
        this.pagination.page = 1;
      }
      this.ChildList = [];
      getOrderChildList({ ...this.ser, ...this.pagination }).then((res) => {
        if (res.code == 200) {
          this.ChildList = res.data.data;
          this.total = res.data.total;
          if (type == 2) {
            if (res.data.data.length > 0) {
              this.$message.success("正在导出订单列表");
              this.exports_w();
            }
          }
        }
      });
    },
    // 导出
    exports_w() {
      let data = {
        ...this.ser,
        export: 1,
      };
      getOrderChildList_exports(data).then((res) => {
        //创建一个隐藏的a连接，
        const link = document.createElement("a");
        let blob = new Blob([res.data], { type: "application/vnd.ms-excel" });
        link.style.display = "none";
        //设置连接
        link.href = URL.createObjectURL(blob);
        link.download = "订单信息";
        document.body.appendChild(link);
        //模拟点击事件
        link.click();
      });
    },
    searchreset() {
      this.ser = {
        model_number_id: "",
        order_number: "",
        customer_id: "",
        product_id: "",
        order_date: "",
        is_replenishment: "",
        is_stock_up: "",
        start_time: "",
        end_time: "",
      };
      this.get_childList();
    },
    //客户列表
    getCustomer() {
      getCustomerList().then((res) => {
        if (res.code == 200) {
          this.CustomerList = res.data.data;
        }
      });
    },
    //产品列表
    getproduct() {
      getProductList().then((res) => {
        if (res.code == 200) {
          this.productList = res.data.data;
        }
      });
    },
    // 型号列表
    getModel() {
      getModelNumberList().then((res) => {
        if (res.code == 200) {
          this.ModelNumberLists = res.data.data;
        }
      });
    },
    order_data_change(val) {
      this.ser.start_time = val[0];
      this.ser.end_time = val[1];
    },
    get_producModel(id) {
      getModelNumberList({ product_id: id, field_list: 'id,model_number', is_dropdown: 1 }).then((res) => {
        if (res.code == 200) {
          this.ModelNumberList = res.data.data;
        }
      });
    },
    product_id_change(val) {
      this.ser.model_number_id = "";
      this.get_producModel(val)
    },
    // 获取子订单
    get_childList() {
      getOrderChildList({ ...this.pagination, ...this.ser }).then((res) => {
        if (res.code == 200) {
          this.ChildList = res.data.data;
          this.total = res.data.total;
          this.loading = false;
        }
      });
    },
    //设置订单为已完成
    push_set_1() {
      setOrderChildStatus({
        child_order_id: this.push_order.id,
        employee_user_id: this.push_order.employee_user_id,
      }).then((res) => {
        if (res.code == 200) {
          this.$message({
            type: "success",
            message: "操作成功",
          });
          this.get_childList();
          this.isset_1 = false;
        }
      });
    },

    //获取指定工种员工列表
    async getUser(id) {
      var istrue
      // await getUserListByModelNumberId({ job_type_id: id, model_number_id: this.model_number_idsss }).then(res => {
      //   if (res.code == 200) {
      //     if (res.data.length > 0) {
      //       this.pushCustomerList = res.data;
      //       istrue = true
      //     } else {
      //       istrue = false
      //     }
      //   }
      // })
      // await getUserListByModelNumberId({ job_type_id: id}).then(res => {
      //   if (res.code == 200) {
      //     if (res.data.length > 0) {
      //       this.pushCustomerList = res.data;
      //       istrue = true
      //     } else {
      //       istrue = false
      //     }
      //   }
      // })

      await getUserListByJobTypeId({ job_type_id: id }).then((res) => {
        if (res.code == 200) {
          this.pushCustomerList = res.data;
          console.log( this.pushCustomerList)
          istrue = true
        } else {
          istrue = false
        }
      });

      return istrue
    },
    close_dialog() {
      this.push_order = {
        id: "",
        employee_user_id: "",
        job_type: {},
      };
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pagination.per_page = val
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pagination.page = val;
      this.get_childList();
    },
    prev() {
      this.pagination.page = this.pagination.page - 1;
      this.get_childList();
    },
    next() {
      this.pagination.page = this.pagination.page + 1;
      this.get_childList();
    },
    // 获取对应子订单信息
    getOrderChild(id) {
      this.order_ids = id;
      getOrderChildListByOrderId({ order_id: id }).then((res) => {
        if (res.code == 200) {
          // this.moreLists=res.data
          this.moreList = res.data;
        }
      });
    },
    //指派订单大弹窗
    set_products(row) {
      this.model_number_idsss = row.model_number_id
      this.moreLists = row;
      this.getOrderChild(row.id);
      this.isProducts = true;
    },
    // 外包提交
    set_waibaos(row) {
      epibolyOrderChild({ child_order_id: row.id }).then((res) => {
        if (res.code == 200) {
          this.$message.success("外包成功");
          this.getOrderChild(this.moreLists.id);
          this.get_childList();
        }
      });
    },
    // //获取指定工种员工列表
    // getUser(id) {
    //   getUserListByJobTypeId({ job_type_id: id }).then((res) => {
    //     if (res.code == 200) {
    //       this.pushCustomerList = res.data;
    //     }
    //   });
    // },
    // 双击打开
    db_pushorder(row, rows) {
      console.log(rows)
      this.model_number_idsss = rows.model_number_id
      if (row.status != 1) {
        // this.getUser(row.job_type.id);
        this.getUser(row.job_type.id).then(res => {
          console.log(res)
          if (res == true) {
            this.isset_1 = true;
          } else {
            this.$message.error("没有对应员工！");
          }
        })
        this.push_order = row;
        if (row.employee) {
          this.push_order.employee_user_id = row.employee.user_id;
        }
      }
    },
    //打开指派弹窗
    setqx_yuangong(row) {
      console.log(row)
      cancelAssignOrderChild({ order_child_id: row.id }).then(res => {
        if (res.code == 200) {
          this.$message.success("取消成功！");
          this.get_childList();
        }
      })
    },
    set_yuangong(row) {
      this.push_more = row;
      this.push_prder.child_order_id = row.id;
      this.getUser(row.job_type.id).then(res => {
        console.log(res)
        if (res == true) {
          this.isset = true;

        } else {
          this.$message.error("没有对应员工！");
        }
      })

    },
    // 指派提交
    push_set() {
      assignOrderChild(this.push_prder).then((res) => {
        this.$message.success("指派成功");
        this.isset = false;
        this.getOrderChild(this.moreLists.id);
        this.push_prder = {
          child_order_id: "",
          employee_user_id: "",
        };
        this.get_childList();
      });
    },
  },
};
</script>
<style>
.my-label {
  background: #e1f3d8;
}

/* .my-content {
    background: #dd7575;
    color: #fff;
  } */

.ul {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
  margin-bottom: 10px;
}

.li {
  width: 32.5%;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -ms-box-sizing: border-box;
  -o-box-sizing: border-box;
  overflow: hidden;
  margin-top: 16px;
  margin-left: 1.02%;
}

.li:nth-child(3n-2) {
  margin-left: 0;
}

.uls {
  width: 100%;
  max-width: 100%;
  overflow-x: scroll;
  white-space: nowrap;
}

.uls .lis {
  display: inline-block;
  margin-left: 0px;
  margin-top: 5px;
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -ms-box-sizing: border-box;
  -o-box-sizing: border-box;
  border: 1px solid #fff;
  border-radius: 5px;
}

.uls .lis span {
  display: block;
  font-size: 14px;
  width: 100%;
  text-align: center;
  cursor: pointer;
  line-height: 16px;
}

.uls .lis span:nth-child(2) {
  /* margin-top: px; */
}

.wancheng {
  background: #1aa034;
  color: #fff;
}

.unwancheng {
  background: #1b8bf5;
  color: #fff;
}

.unpush {
  background: #ff6561;
  color: #fff;
}

.unwanchengs {
  background: #902c90;
  color: #fff;
}

/* .el-descriptions .is-bordered .el-descriptions-item__cell{
  padding: 5px!important;
} */

.lable_width {
  width: 100px;
}

.el-table .el-table__cell {
  /* padding: 5px 0 !important; */
}

.el-dropdown-menu {
  text-align: center;
}


.el-dropdown-menu .el-button--text {
  width: 100%;
}
</style>
